package com.ygqh.baby.service.impl;

import java.util.Date;
import java.util.List;

import com.ygqh.baby.ao.QueryInfo;
import com.ygqh.baby.ao.ResultSet;
import com.ygqh.baby.po.YgStockWhiteList;
import com.ygqh.baby.mapper.YgStockWhiteListMapper;
import com.ygqh.baby.service.YgStockWhiteListService;

import org.springframework.util.Assert;

import java.util.Arrays;

import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

import com.ygqh.baby.po.YgStockWhiteListExample;
import com.ygqh.baby.ao.DataStatus;

@Service
public class YgStockWhiteListServiceImpl implements YgStockWhiteListService {

	@Autowired
	private YgStockWhiteListMapper ygStockWhiteListMapper;

	@Override
	public List<YgStockWhiteList> find() {
		YgStockWhiteListExample example = new YgStockWhiteListExample();
		example.createCriteria().andStatusEqualTo(DataStatus.Valid.name());
		return ygStockWhiteListMapper.selectByExample(example);
	}

	@Override
	public int findCount() {
		YgStockWhiteListExample example = new YgStockWhiteListExample();
		example.createCriteria().andStatusEqualTo(DataStatus.Valid.name());
		return ygStockWhiteListMapper.countByExample(example);
	}

	@Override
	public YgStockWhiteList findById(Long id) {
		return ygStockWhiteListMapper.selectByPrimaryKey(id);
	}

	@Override
	public int save(YgStockWhiteList ygStockWhiteList) {
		return ygStockWhiteListMapper.insertSelective(ygStockWhiteList);
	}

	@Override
	public int update(YgStockWhiteList ygStockWhiteList) {
		return ygStockWhiteListMapper.updateByPrimaryKeySelective(ygStockWhiteList);
	}

	@Override
	public ResultSet<YgStockWhiteList> search(QueryInfo queryInfo, Date startDate, Date endDate, String q) {
		List<YgStockWhiteList> list = ygStockWhiteListMapper.selectSuper(queryInfo, startDate, endDate, q);
		int count = ygStockWhiteListMapper.countSuper(startDate, endDate, q);
		ResultSet<YgStockWhiteList> resultSet = new ResultSet<YgStockWhiteList>(count, list);
		return resultSet;
	}

	@Override
	public int deleteSoft(Long[] ids) {
		Assert.notEmpty(ids);
		YgStockWhiteListExample example = new YgStockWhiteListExample();
		example.createCriteria().andIdIn(Arrays.asList(ids));
		YgStockWhiteList record = new YgStockWhiteList();
		record.setStatus(DataStatus.Delete);

		return ygStockWhiteListMapper.updateByExampleSelective(record, example);
	}

	@Override
	public int deleteSoft(Long id) {
		return this.deleteSoft(new Long[] { id });
	}

	@Override
	public int saveOrUpdate(YgStockWhiteList ygStockWhiteList) {
		int r = 0;
		if (ygStockWhiteList.getId() != null) {
			r = this.update(ygStockWhiteList);
		} else {
			r = this.save(ygStockWhiteList);
		}
		return r;
	}

	@Override
	public YgStockWhiteList findStockWhiteOnLine() {
		return ygStockWhiteListMapper.selectStockWhiteOnLine();
	}

}
